package com.gator.desig_mode.mediator;



import java.util.HashMap;
import java.util.Map;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc //中介者抽象  完成智能家居的协调工作
 */
public abstract class Mediator {

  abstract void register(String key, Colleague value);

  abstract void sendMessage();

  abstract void getMessage(String info, String name);
}

class ConcreteMediator extends Mediator {

  private Map<String, Colleague> map = new HashMap<>();


  @Override
  void register(String key, Colleague value) {
    map.put(key, value);
  }

  @Override
  void sendMessage() {

  }
  /**
   @describe  核心中介方法，协调所有同事
   @return
   @author 何章怀晓 hezhanghuaixiao
   @date 2022/3/16  21:50
   @other
   */
  void getMessage(String info, String name) {
    //该方法为核心方法，将根据信息info处理接下来的一系列操作
    Colleague colleague = map.get(name);
    if (colleague instanceof Alarm) {
      System.out.println(name + "发来信息" + info);
      //假设闹钟响了，就打开电视
      TV tv = (TV) map.get("tv");
      tv.openTv();
      //其他联动逻辑
    }
    //......
    //......

  }


}
